﻿using System.Windows;
using System.Windows.Controls;
using ZOIL.Framework.Presentation;

namespace ZOIL.Library.Components.LazyLoadingContainer
{
    public class LazyLoadingContainer : ZComponent
    {
        #region dependency properties

        #region TitleTemplate

        // Using a DependencyProperty as the backing store for TitleTemplate.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty TitleTemplateProperty =
            DependencyProperty.Register("TitleTemplate", typeof (ControlTemplate), typeof (LazyLoadingContainer),
                                        new UIPropertyMetadata(null, OnTitleTemplateChanged));

        public ControlTemplate TitleTemplate
        {
            get { return (ControlTemplate) GetValue(TitleTemplateProperty); }
            set { SetValue(TitleTemplateProperty, value); }
        }

        private static void OnTitleTemplateChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
        }

        #endregion

        #region DynamicTemplate

        // Using a DependencyProperty as the backing store for DynamicTemplate.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty DynamicTemplateProperty =
            DependencyProperty.Register("DynamicTemplate", typeof (ControlTemplate), typeof (LazyLoadingContainer),
                                        new UIPropertyMetadata(null, OnDynamicTemplateChanged));

        public ControlTemplate DynamicTemplate
        {
            get { return (ControlTemplate) GetValue(DynamicTemplateProperty); }
            set { SetValue(DynamicTemplateProperty, value); }
        }

        private static void OnDynamicTemplateChanged(object sender, DependencyPropertyChangedEventArgs args)
        {
        }

        #endregion

        #endregion

        public override void UpdateRepresentation()
        {
            UpdateVisibility();

            if (RenderedSize.Width < 600)
            {
                if (Template != TitleTemplate)
                {
                    Template = TitleTemplate;
                }
            }
            else
            {
                if (Template != DynamicTemplate)
                {
                    Template = DynamicTemplate;
                }
            }
        }
    }
}